package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	PhoneNum      string `gorm:"type:varchar(255);not null;comment:手机号"`
	Pwd           string `gorm:"type:varchar(500);not null;comment:密码"`
	NickName      string `gorm:"type:varchar(500);not null;comment:昵称"`
	AvatarLink    string `gorm:"type:varchar(500);not null;comment:头像URL"`
	AccountStatus string `gorm:"type:varchar(255);default:0;not null;comment:账号状态,0-正常，1-禁用"`
	FollowNum     int64  `gorm:"type:int(11);default:0;not null;comment:关注数"`
	FansNum       int64  `gorm:"type:int(11);default:0;not null;comment:粉丝数"`
}

func (u *User) FindPhone(db *gorm.DB, num string) error {
	return db.Debug().Where("phone_num = ?", num).First(u).Error
}

func (u *User) AddUser(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) UpdatePwd(db *gorm.DB, num string) error {
	return db.Debug().Where("phone_num = ?", num).Updates(u).Error
}

func (u *User) FindUserId(db *gorm.DB, id int64) error {
	return db.Debug().Where("users.id = ?", id).First(u).Error
}
